package com.sprucetec.live.service.impl;

import com.sprucetec.live.common.webcontext.LoginUserContext;
import com.sprucetec.live.entity.LiveVideoHlsDetail;
import com.sprucetec.live.entity.LiveVideoRelateDetail;
import com.sprucetec.live.entity.LiveVideoServerDetail;
import com.sprucetec.live.enums.DeleteStatusEnum;
import com.sprucetec.live.mapper.LiveVideoRelateDetailMapper;
import com.sprucetec.live.service.LiveVideoRelateDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

/**
 * @author chenkai
 * @date 2020/3/31 4:37 下午
 * @description:
 */
@Slf4j
@Service("liveVideoRelateDetailService")
public class LiveVdeoRelateDetailServiceImpl implements LiveVideoRelateDetailService {

    @Autowired
    private LiveVideoRelateDetailMapper liveVideoRelateDetailMapper;

    @Override
    public void batchInsert(List<LiveVideoRelateDetail> list) {
        liveVideoRelateDetailMapper.batchInsert(list);
    }

    @Override
    public void deleteRelateDetail(Long liveVideoId) {
        Example example = new Example(LiveVideoServerDetail.class);
        example.createCriteria().andEqualTo("liveVideoId", liveVideoId);

        LiveVideoRelateDetail videoRelateDetail = new LiveVideoRelateDetail();
        videoRelateDetail.setIsDeleted(DeleteStatusEnum.DELETED.getCode());
        videoRelateDetail.setUpdateTime(new Date());
        videoRelateDetail.setUpdateUserCode(LoginUserContext.getUser().getUid());
        videoRelateDetail.setUpdateUserName(LoginUserContext.getUser().getName());
        liveVideoRelateDetailMapper.updateByExampleSelective(videoRelateDetail, example);
    }

    @Override
    public List<LiveVideoRelateDetail> getRelateDetailList(Long liveVideoId) {
        Example example = new Example(LiveVideoServerDetail.class);
        example.createCriteria().andEqualTo("liveVideoId", liveVideoId).andEqualTo("isDeleted", DeleteStatusEnum.VALID.getCode());
        return liveVideoRelateDetailMapper.selectByExample(example);
    }
}
